{
 "cells": [
  {
   "cell_type": "code",
   "id": "initial_id",
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2025-11-14T08:48:10.042407Z",
     "start_time": "2025-11-14T08:48:10.018444Z"
    }
   },
   "source": [
    "from datetime import datetime\n",
    "\n",
    "import pandas as pd\n",
    "date_index=pd.to_datetime(['20230110','20230115','20230118'])\n",
    "date_ser=pd.Series([11,22,33],index=date_index)\n",
    "date_ser"
   ],
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2023-01-10    11\n",
       "2023-01-15    22\n",
       "2023-01-18    33\n",
       "dtype: int64"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 8
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-11-14T09:11:43.981399Z",
     "start_time": "2025-11-14T09:11:43.945981Z"
    }
   },
   "cell_type": "code",
   "source": [
    "from datetime import datetime\n",
    "data_demo=[[11,22,33],[44,55,66],[77,88,99],[12,23,34]]\n",
    "date_list=[datetime(2023,1,23),datetime(2023,2,15),\n",
    "           datetime(2023,5,22),datetime(2023,3,30)]\n",
    "time_df= pd.DataFrame(data_demo, index=date_list)\n",
    "time_df"
   ],
   "id": "219e7e1e04cf98dd",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "             0   1   2\n",
       "2023-01-23  11  22  33\n",
       "2023-02-15  44  55  66\n",
       "2023-05-22  77  88  99\n",
       "2023-03-30  12  23  34"
      ],
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2023-01-23</th>\n",
       "      <td>11</td>\n",
       "      <td>22</td>\n",
       "      <td>33</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-02-15</th>\n",
       "      <td>44</td>\n",
       "      <td>55</td>\n",
       "      <td>66</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-05-22</th>\n",
       "      <td>77</td>\n",
       "      <td>88</td>\n",
       "      <td>99</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-03-30</th>\n",
       "      <td>12</td>\n",
       "      <td>23</td>\n",
       "      <td>34</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 12
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-11-14T09:17:14.446852Z",
     "start_time": "2025-11-14T09:17:14.429640Z"
    }
   },
   "cell_type": "code",
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "date_list=['2020/05/30','2022/02/01','2020/6/1','2021/4/1','2022/6/1','2023/1/23']\n",
    "date_index=pd.to_datetime(date_list)\n",
    "date_ser=pd.Series(np.arange(6),index=date_index)\n",
    "date_ser"
   ],
   "id": "583fb85a9ee943f5",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2020-05-30    0\n",
       "2022-02-01    1\n",
       "2020-06-01    2\n",
       "2021-04-01    3\n",
       "2022-06-01    4\n",
       "2023-01-23    5\n",
       "dtype: int64"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 13
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-11-14T09:18:10.896234Z",
     "start_time": "2025-11-14T09:18:10.854262Z"
    }
   },
   "cell_type": "code",
   "source": "date_ser['2020']",
   "id": "56f503726b573b17",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2020-05-30    0\n",
       "2020-06-01    2\n",
       "dtype: int64"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 14
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-11-14T09:19:36.675394Z",
     "start_time": "2025-11-14T09:19:36.658561Z"
    }
   },
   "cell_type": "code",
   "source": "date_ser['2020/05/30']",
   "id": "21eb2b3f6cf51302",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "np.int64(0)"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 15
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-11-14T09:19:37.726461Z",
     "start_time": "2025-11-14T09:19:37.712847Z"
    }
   },
   "cell_type": "code",
   "source": "date_ser['5/30/2020']",
   "id": "398867d2ef1b9cfb",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "np.int64(0)"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 16
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-11-14T09:35:02.328535Z",
     "start_time": "2025-11-14T09:35:02.306601Z"
    }
   },
   "cell_type": "code",
   "source": [
    "import pandas as pd\n",
    "# 创建DatetimeIndex类的对象，指定起始日期与终止日期\n",
    "date_ran = pd.date_range('2023/01/01', '2023/01/10')\n",
    "date_ran"
   ],
   "id": "3e5f2d1d6b8f5aaf",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "DatetimeIndex(['2023-01-01', '2023-01-02', '2023-01-03', '2023-01-04',\n",
       "               '2023-01-05', '2023-01-06', '2023-01-07', '2023-01-08',\n",
       "               '2023-01-09', '2023-01-10'],\n",
       "              dtype='datetime64[ns]', freq='D')"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 18
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-11-14T09:40:14.359042Z",
     "start_time": "2025-11-14T09:40:14.343653Z"
    }
   },
   "cell_type": "code",
   "source": [
    "date_ran = pd.date_range(end='2023/01/10',periods=5)\n",
    "date_ran"
   ],
   "id": "a1a59f646d648853",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "DatetimeIndex(['2023-01-06', '2023-01-07', '2023-01-08', '2023-01-09',\n",
       "               '2023-01-10'],\n",
       "              dtype='datetime64[ns]', freq='D')"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 19
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-11-14T13:36:26.899784Z",
     "start_time": "2025-11-14T13:36:26.870525Z"
    }
   },
   "cell_type": "code",
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "dates_index = pd.date_range(start='2023-01-01', periods=5, freq='5D')\n",
    "dates_index"
   ],
   "id": "2d86459923fd6ad2",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "DatetimeIndex(['2023-01-01', '2023-01-06', '2023-01-11', '2023-01-16',\n",
       "               '2023-01-21'],\n",
       "              dtype='datetime64[ns]', freq='5D')"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 4
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-11-14T13:36:34.211099Z",
     "start_time": "2025-11-14T13:36:34.207300Z"
    }
   },
   "cell_type": "code",
   "source": [
    "dates_index = pd.date_range(start='2023-01-01 12:30:11',periods=5,\n",
    "freq='5D')\n",
    "dates_index"
   ],
   "id": "4ef1e4e2e75bd7a",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "DatetimeIndex(['2023-01-01 12:30:11', '2023-01-06 12:30:11',\n",
       "               '2023-01-11 12:30:11', '2023-01-16 12:30:11',\n",
       "               '2023-01-21 12:30:11'],\n",
       "              dtype='datetime64[ns]', freq='5D')"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 5
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-11-14T13:37:12.006327Z",
     "start_time": "2025-11-14T13:37:08.672163Z"
    }
   },
   "cell_type": "code",
   "source": "pd.date_range(start='2023/1/1 12:30:11', periods=5, tz='Asia/Hong_Kong', normalize=True)\n",
   "id": "7dc6caf716e89c8f",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "DatetimeIndex(['2023-01-01 00:00:00+08:00', '2023-01-02 00:00:00+08:00',\n",
       "               '2023-01-03 00:00:00+08:00', '2023-01-04 00:00:00+08:00',\n",
       "               '2023-01-05 00:00:00+08:00'],\n",
       "              dtype='datetime64[ns, Asia/Hong_Kong]', freq='D')"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 6
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python [conda env:base] *",
   "language": "python",
   "name": "conda-base-py"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
